package com.unit5;

import com.unit5.pojo.Student;

import java.io.FileInputStream;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.ArrayList;

/**
 * @author 李琦 on 2021/8/13.
 * @version java version "16.0.1" 2021-04-20
 * 对象输入流:ObjectInputStream--将本地文件中的对象读出
 */
public class test9 {
    public static void main(String[] args) {
        ObjectInputStream ois=null;
        try {
            ois=new ObjectInputStream(new FileInputStream("E:\\padata\\stu.txt"));
            ArrayList<Student> stuArray=(ArrayList<Student>)ois.readObject();
            for(Student stu:stuArray){
                System.out.println("姓名:"+stu.name+"   年龄:"+stu.age+"   爱好:"+stu.hobby);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }finally{
            try {
                ois.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }




    }
}
